<template>
  <div style="height: 100%">
    <div style="height: 100%">
      <el-container style="height: 100%">
        <el-aside width="200px">
          <h3>外卖商家中心</h3>
          <el-menu
            :default-active="active"
            class="el-menu-vertical-demo"
            router
            background-color="#304156"
            text-color="#fff"
            active-text-color="#ffd04b"
            unique-opened
          >
            <div v-for="item in rolelist" :key="item.index">
              <el-submenu v-if="item.children" :index="item.index">
                <template slot="title">
                  <i :class="item.icon"></i>
                  <span>{{ item.name }}</span>
                </template>
                <el-menu-item
                  v-for="child in item.children"
                  :key="child.index"
                  :index="child.index"
                  >{{ child.name }}</el-menu-item
                >
              </el-submenu>

              <!-- 不克折叠 -->
              <el-menu-item v-else :index="item.index">
                <i :class="item.icon"></i>
                <span slot="title">{{ item.name }}</span>
              </el-menu-item>
            </div>
          </el-menu>
        </el-aside>
        <el-container>
          <el-header>
            <div>
              <el-breadcrumb
                separator-class="el-icon-arrow-right"
                style="line-height: 50px; height: 50px"
              >
                <el-breadcrumb-item :to="{ path: '/' }"
                  >首页</el-breadcrumb-item
                >
                <el-breadcrumb-item>账号管理</el-breadcrumb-item>
                <el-breadcrumb-item>添加账号</el-breadcrumb-item>
              </el-breadcrumb>
            </div>
            <div
              style="line-height: 50px; height:50px font-size: 16px; display: flex;"
            >
              <p>你好,{{ uersname }}</p>
              <div class="uper" @click="funImg">
                <img :src="headerimg" />
              </div>
            </div>
          </el-header>
          <el-main>
            <el-card> <router-view> </router-view></el-card>
          </el-main>
        </el-container>
      </el-container>
    </div>
  </div>
</template>

<script>
import { checktoken, Perinmation } from "@/apis/user";
export default {
  
  data() {
    return {
      active: "home/main",
      imageUrl: "",
      uersname: "请登录",
      headerimg: "",
      list: [
        {
          index: "/home/main",
          icon: "el-icon-s-home",
          name: "后台首页",
          role: ["super", "normal"],
        },
        {
          index: "/home/ordermanager",
          icon: "el-icon-s-order",
          name: "订单管理",
          role: ["super", "normal"],
        },
        {
          index: "3",
          icon: "el-icon-shopping-bag-1",
          name: "商品管理",
          children: [
            { index: "/home/list", name: "商品列表" },
            { index: "/home/add", name: "商品添加" },
            { index: "/home/cation", name: "商品分类" },
          ],
          role: ["super", "normal"],
        },
        {
          index: "/home/storeManagement",
          icon: "el-icon-s-shop",
          role: ["super"],
          name: "店铺管理",
        },
        {
          index: "5",
          icon: "el-icon-user-solid",
          name: "账号管理",
          role: ["super"],
          children: [
            { index: "/home/accountList", name: "账号列表" },
            { index: "/home/AddAccount", name: "账号添加" },
            { index: "/home/ChangePasw", name: "修改密码" },
          ],
        },
        {
          index: "6",
          icon: "el-icon-pie-chart",
          name: "销售统计",
          role: ["super"],
          children: [
            { index: "/home/ShopStatistics", name: "商品统计" },
            { index: "/home/OrderStatistics", name: "订单统计" },
          ],
        },
      ],
    };
  },
  created() {
    this.active = this.$route.path; //
    // this.$router  //全局
    //token
    checktoken({ token: localStorage.token }).then((res) => {
      if (res.data.code == 0) {
        this.uersname = localStorage.acc;
      } else {
        this.uersname = "请登录";
      }
    });
    //头像上传
    Perinmation({ id: localStorage.id }).then((res) => {
      // console.log(res);
      this.headerimg = res.data.accountInfo.imgUrl;
      //存入用户信息
      sessionStorage.accifo= JSON.stringify( res.data.accountInfo)
      // console.log(this.headerimg);
    });

  this.$bus.on('headersuccess',(data)=>{
    console.log(data);
    let oldheaderimg=this.headerimg
    let serverIP =oldheaderimg.substring(0,oldheaderimg.lastIndexOf('/')+1)
    this.headerimg=serverIP+data.imgUrl;
  })

  },

  computed: {
    rolelist() {
      return this.list.filter((obj) =>   obj.role.includes(localStorage.role)
      );
       
    },
  },
  methods: {
    funImg() {
      this.$router.push("/home/Personal");
    },
  },
};
</script>

<style lang="less" scoped>
a {
  color: #fff;
  text-decoration: none;
}

.el-header {
  background-color: #fff;
  color: #333;
  height: 44px !important;
  // text-align: center;
  // line-height: 60px;
  display: flex;
  justify-content: space-between;
}

.el-aside {
  background-color: #304156;
  color: #fff;
  height: 100%;
  h3 {
    font-size: 20px;
    font-weight: normal;
    text-align: center;
    margin-top: 20px;
  }
}

.el-main {
  background-color: #e9eef3;
  // color: #333;
  text-align: center;
  line-height: 160px;
  // display: flex;
  // flex: 1;
}
body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}
.el.menu {
  border: 0;
}
//头像
.uper {
  width: 42px;
  height: 42px;
  border-radius: 21px;
  background-color: #000;
  margin-left: 10px;
  img {
    width: 42px;
    height: 42px;
    border-radius: 21px;
  }
}

//头像
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 21px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 42px;
  height: 42px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 42px;
  height: 42px;
  display: block;
}
.avatar[data-v-fae5bece] {
  border-radius: 21px;
}
</style>